﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace bank
{
    internal class ATM
    {
        private Bank bank;
        public ATM(Bank bank) 
        {
            this.bank = bank;
        }

        public void Transaction()
        {
            Show("请输入卡号");
            string id = GetInput();
            Show("请输入密码");
            string password = GetInput();
            Account myAccount = bank.FindAccount(id);
            if(myAccount != null && myAccount.password == password)
            {
                Show("1.查询金额 2.存款 3.取款");
                string choose = GetInput();
                if(choose.Equals("1"))
                {
                    Show("当前金额:" + myAccount.balance);
                    return;
                } else if(choose.Equals("2"))
                {
                    Show("输入要存的金额");
                    double inBalance = double.Parse(GetInput());
                    myAccount.balance += inBalance;
                    Show("存款成功");
                    Show("当前金额:" + myAccount.balance.ToString());
                    return;
                } else if (choose.Equals("3"))
                {
                    Show("输入要取出的金额");
                    double outBalance = double.Parse(GetInput());
                    myAccount.balance -= outBalance;
                    Show("取款成功");
                    Show("当前金额:" + myAccount.balance.ToString());
                    return;
                } else
                {
                    return;
                }
            } else
            {
                Show("无效的卡号或密码");
                return;
            }

        }

        private void Show(string message)
        {
               Console.WriteLine(message);
        }
        private string GetInput() 
        {
            return Console.ReadLine();
        }
    }
}
